
#include "Arduino.h"
#include "IPAddress.h"
#include "EthernetClient.h"
#include "EthernetServer.h"
#include <EthernetUdp.h>

#include "HomeSensorNet.h"

HomeSensorNet_class::HomeSensorNet_class()
{
}

void HomeSensorNet_class::begin(EthernetUDP* udp,IPAddress broadcast, byte stationID)
{
  _udp = udp;
  _broadcast = broadcast;
  _stationID = stationID;
}

void HomeSensorNet_class::beginTransmission()
{
  _udp -> beginPacket(_broadcast, 9999);
  _udp -> write(_stationID);           //Station ID
  unsigned long time = 0;
  _udp -> write(time);   //Station Time - 0 for now until local time is implemented
}

void HomeSensorNet_class::endTransmission()
{
  _udp -> endPacket();
}

void HomeSensorNet_class::sendSensor (byte SensorID, byte SensorType, int Value)
{
  _udp->write(SensorID);
  _udp->write(SensorType);
  _udp->write(Value); 
}

void HomeSensorNet_class::sendSensor (byte SensorID, byte SensorType, long int Value)
{
  _udp->write(SensorID);
  _udp->write(SensorType);
  _udp->write(Value); 
}

void HomeSensorNet_class::sendSensor (byte SensorID, byte SensorType, byte Value)
{
  _udp->write(SensorID);
  _udp->write(SensorType);
  _udp->write(Value); 
}

HomeSensorNet_class HomeSensorNet;
